package com.hc.contorl;

import com.hc.service.TbUserService;
import com.hc.service.impl.TbUserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(value = "/deleteArray")
public class UserArrayDeleteContorller extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");

        String pageNum=req.getParameter("pageNum");
        String pageSize=req.getParameter("pageSize");
        String[] ids = req.getParameter("ids").split(",");
        TbUserService service = new TbUserServiceImpl();
        int line = service.batchDelete(ids);
        if (line > 0) {
            req.setAttribute("message", "删除成功");

        } else {
            req.setAttribute("message", "删除失败");
        }
        req.getRequestDispatcher(String.format("/user_list?pageNum=%s&pageSize=%s",pageNum,pageSize)).forward(req, resp);
    }
}
